package com.wechatnotice.wechatnotice.controller;

import cn.hutool.core.date.DateUtil;
import com.wechatnotice.wechatnotice.service.NoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *
 * </p>
 *
 * @program: WechatNotice
 * @author: daPangDong
 * @create: 2022-10-27 18:21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/wechatNotice")
public class WechatNoticeController {

    private final RestTemplate restTemplate;
    private final NoticeService noticeService;


    @PostMapping("toSend")
    public Object send(){
        Map<String,Object> msg = new HashMap<>(3);
        msg.put("content","<font color=\"warning\">程序正在部署</font>，请相关同事注意。\n>" +
                "服务:<font color=\"comment\">用户反馈</font>");

        Map<String,Object> body = new HashMap<>(3);
        body.put("msgtype","markdown");
        body.put("markdown",msg);
        ResponseEntity<Map> response = restTemplate.postForEntity(
                "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=b5fdb41a-24df-4da8-8a65-16e4476575e0",
                body,
                Map.class);
        return response;
    }

    @GetMapping("/sendMail")
    public Object sendMail(){
        return noticeService.sendMail("1131310045@qq.com","测试","文件");
    }

    @GetMapping("/sendHtmlToMail")
    public Object sendHtmlToMail(){
        return noticeService.sendHtmlToMail("1131310045@qq.com","系统通知");
    }


    public static void main(String[] args) {
        System.out.println(DateUtil.dayOfWeekEnum(new Date()));
        System.out.println(DateUtil.dayOfYear(new Date()));
        System.out.println(DateUtil.dayOfMonth(new Date()));
        System.out.println(DateUtil.quarterEnum(new Date()));
        System.out.println(DateUtil.beginOfYear(new Date()));
        System.out.println(DateUtil.yesterday());
    }
}
